<template>
  <div class="swiper-container">
    <div class="swiper-wrapper">
      <div class="swiper-slide" v-for="(slid,index) in skuImageList" :key="slid.id">
        <img :src="slid.imgUrl" :class="{active:index===currentIndex}" @click="showBorder(index)"/>
      </div>
    </div>
    <div class="swiper-pagination"></div>

    <!-- 如果需要导航按钮 -->
    <div class="swiper-button-prev"></div>
    <div class="swiper-button-next"></div>
  </div>
</template>

<script>
import Swiper from "swiper";
export default {
  name: "imageList",
  data(){
    return{
      currentIndex:0,
    }
  },
  props:['skuImageList'],
  methods:{
    showBorder(index){
      this.currentIndex=index
      this.$emit('imageIndex',index)
    }
  },
  watch:{
    skuImageList: {
      handler(newValue, oldValue) {
        this.$nextTick(() => {//有时可以直接放在mounted里面(当里面的数据非常少，请求速度快时(可能显示不清),或者是在父组件中已经请求到了数据
          //直接传递来的值 )
          let mySwiper = new Swiper('.swiper-container', {
            navigation: {
              nextEl: '.swiper-button-next',
              prevEl: '.swiper-button-prev',
            },
            slidesPerView: 5,
            slidesPerGroup:1
          })
        })
      }
    }
  }
}
</script>

<style scoped lang="less">
.active{
  border: 2px solid #f60;
}
.swiper-button-next {
  width: 10px !important;
  height: 54px !important;
  background: #ebebeb;
  border: 1px solid #ccc;
top:20px;
  bottom: 0;
  left:400px
}
.swiper-button-next:after{
  font-size: 12px!important;
}
.swiper-button-prev:after{
  font-size: 12px!important;
}
.swiper-button-prev{
  width: 10px !important;
  height: 54px !important;
  background: #ebebeb;
  border: 1px solid #ccc;
  top:20px;
  bottom: 0;
left: 0px!important;
}
.swiper-slide{
  width: 56px!important;
  margin-left:11px;
  margin-right: 15px;
}
  .swiper-container{
    width: 412px;
    height: 56px;
  }
  img{
    width: 50px;
    height: 50px;
    padding: 1px;
    border: 1px solid #ccc;
  }
</style>
